<!DOCTYPE html>
<html lang="en">
<head>
    {template 'common/listhead'}

    <!--微擎 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>


</head>
</head>

<body class="nav-md">
<div class="container body">

    <div class="main_container xc_edit_from"  style="overflow-x: hidden;min-height: 100vh;background-color: white">
        <div class="">

            <div class="col-md-12 col-sm-12 col-xs-12">

                <div class="panel panel-info">
                    <div class="panel-heading">筛选</div>
                    <div class="panel-body">
                        <form action=" " method="get" class="form-horizontal" role="form" id="searchform">

                            <div class="col-xs-12 col-sm-3 col-md-3col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon">用户id</span>
                                    <input class="form-control" name="openid">
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-3 col-md-3col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon">订单号</span>
                                    <input class="form-control" name="out_trade_no">
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-3 col-md-3col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon">状态</span>
                                    <select  class="form-control js-select2" name="status">
                                        <option value="">请选择状态</option>
                                        <option value="-1">待处理</option>
                                        <option value="1">成功</option>
                                        <option value="1">失败</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-3 col-md-3col-lg-3">
                                <div class="input-group">
                                    <span class="input-group-addon">申请时间</span>
                                    {php echo tpl_form_field_daterange('times',$times,true);}
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
                                <button class="btn btn-default" type="button" id="btnseach"><i class="fa fa-search"></i> 搜索</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>

            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>   {$xtitleb}  > {$xtitlea}列表</h2>

                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">

                        <div class="ibox-content" id="pfrom">
                            <!--data-detail-view="true"   data-detail-formatter="detailFormatter"-->
                            <table id="table" class="dotable" data-toggle="table"
                                   data-url="{php echo $this->createWebUrl($do, array('op'=>'share_withdraw_getseachjson'));}"
                                   data-sort-name="id" data-sort-order="desc" data-query-params="queryparams"
                                   data-page-number="1" data-page-size="15" data-mobile-responsive="true">
                                <thead>
                                <tr>
                                    <th data-checkbox="true"></th>
                                    <th data-field="openid" data-sortable="true">用户id</th>
                                    <th data-field="out_trade_no" data-sortable="true">订单号</th>
                                    <th data-field="type" data-sortable="true" data-formatter="type_name">提现方式</th>
                                    <th data-field="amount" data-sortable="true">提现金额</th>
                                    <th data-field="fee" data-sortable="true">手续费</th>
                                    <th data-field="" data-sortable="true" data-formatter="info">信息</th>
                                    <th data-field="createtime" data-sortable="true">申请时间</th>
                                    <th data-field="status" data-sortable="true" data-formatter="status">状态</th>
                                    <th data-events="operateEvents" data-formatter="operateFormatter" data-width="10%"
                                        data-title="操作" data-align="center">操作
                                    </th>
                                </tr>
                                </thead>
                            </table>
                            <a class="btn btn-info" data-toggle="modal" data-target="#selectUrl" style="margin-right:5px;">导出Excel</a>
                            <br>
                            <!--<br>-->
                            <!--说明：-->
                            <!--<a class="btn btn btn-default btn-xs"> <i class="fa fa-square-o fa-lg"></i></a>禁用 <a-->
                            <!--class="btn btn-primary  btn-xs"> <i class="fa fa-check-square-o fa-lg"></i></a> 开启-->
                        </div>

                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<!--导出-->
<div class="modal fade" id="selectUrl"><div class="modal-dialog">
    <style>
        #selectUrl #selectUrlTab{margin-bottom: 10px;}
        #selectUrl nav{margin-bottom:5px;}
    </style>
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
            <h4 class="modal-title">选择导出字段</h4>
        </div>
        <div class="modal-body">
            <ul class="nav nav-tabs" id="selectUrlTab">
                <li role="presentation" class="active"><a href="#sut_page">字段</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="sut_page">
                    {loop $export_field $index $item}
                    <nav class="btn btn-default btn-sm" data-status="-1" data-name="{$index}" title="{$item}">{$item}</nav>
                    {/loop}
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" id="select-btn" type="button">导出</button>
            <button data-dismiss="modal" class="btn btn-default" id="select-close" type="button">关闭</button>
        </div>
        <script>
            $(function(){
                $("#selectUrl .modal-body nav").click(function(){
                    var status=$(this).attr("data-status");
                    if(status==1){
                        $(this).removeClass("btn-primary").addClass("btn-default");
                    }else if(status==-1){
                        $(this).removeClass("btn-default").addClass("btn-primary");
                    }
                    $(this).attr("data-status",-status);
                });
                $("#select-btn").click(function(){
                    var data=[];
                    $("#selectUrl .modal-body").find("nav").each(function(){
                        var status=$(this).attr("data-status");
                        var name=$(this).attr("data-name");
                        var title=$(this).attr("title");
                        var data2={name:title,key:name,status:status};
                        data.push(data2);
                    });
                    var url="{$export_url}";
                    var param=$("#searchform").serialize();
                    url=url+'&xc='+JSON.stringify(data)+'&'+param;
                    location.href=url;
                    $("#select-close").click();
                });
            });
        </script>
    </div>
</div></div>
<!--导出 end-->
{template 'common/listfoot'}
<script type="text/javascript">
    $(".ajax-select").select2({
        language:'zh-CN',
        ajax: {
            url: "{php echo $this->createWebUrl($do, array('op'=>'getseachselect'));}",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    q: params.term, // search term
                    page: params.page
                };
            },
            processResults: function (data, params) {

//                console.log(data);
//             console.log("AAAAAAAAAAAAAAAA");
//                return {
//                    results: data
//                };



                // parse the results into the format expected by Select2
                // since we are using custom formatting functions we do not need to
                // alter the remote JSON data, except to indicate that infinite
                // scrolling can be used
                params.page = params.page || 1;
                return {
                    results: data.rows,
                    pagination: {
                        more: (params.page * 30) < data.total
                    }
                };

//
//                params.page = params.page || 1;
//                return {
//                    results: data.rows,
//                    pagination: {
//                        more: (params.page * 30) < data.total
//                    }
//                };
            },
            cache: true
        },
        placeholder: '请选择分类',
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 0,
        templateResult: formatRepo,
        templateSelection: formatRepoSelection
    });

    function formatRepo (repo) {

        if (repo.loading) {
            return repo.text;
        }
        return repo.text;
//这里可以自定义返回格式
//        console.log(repo);
//        var markup = "<div class='select2-result-repository clearfix'>" +
//            "<div class='select2-result-repository__avatar'><img src='" + repo.owner.avatar_url + "' /></div>" +
//            "<div class='select2-result-repository__meta'>" +
//            "<div class='select2-result-repository__title'>" + repo.full_name + "</div>";
//
//        if (repo.description) {
//            markup += "<div class='select2-result-repository__description'>" + repo.description + "</div>";
//        }
//
//        markup += "<div class='select2-result-repository__statistics'>" +
//            "<div class='select2-result-repository__forks'><i class='fa fa-flash'></i> " + repo.forks_count + " Forks</div>" +
//            "<div class='select2-result-repository__stargazers'><i class='fa fa-star'></i> " + repo.stargazers_count + " Stars</div>" +
//            "<div class='select2-result-repository__watchers'><i class='fa fa-eye'></i> " + repo.watchers_count + " Watchers</div>" +
//            "</div>" +
//            "</div></div>";
//
//        return markup;
    }
    function formatRepoSelection (repo) {
        return repo.text || repo.id;
    }
    var htojb={};
    $saechparas=null;
    $(function () {
        $("#btnseach").click(function () {
            setseach()
            $("#table").bootstrapTable('refresh');
        })
        $(".js-select2").select2({ theme: "bootstrap"});
        var htpid={};
        $('[name="pid"]').find("option").each(function () {
            htpid[$(this).attr("value")]=$(this).text();
        })

        htojb["pid"]=htpid;
    })
    function setseach() {
        $saechparas = {};
        $saechparas = $("#searchform").serializeArray();

    }
    function queryparams(params) {

        if ($saechparas == null) {
            setseach()
        }

        $.each($saechparas, function (i, field) {
            if(field.name.indexOf("[]")>0){

                var kname=field.name.replace("[]","");
                if( typeof(params[kname]) ==="undefined"){
                    params[kname]=[];
                }
                params[kname].push(field.value)
            }
            else
            {
                params[field.name] = field.value;
            }

        });

        return params;
    }
    $(function () {
        $("#delselct").click(function () {

            $pdadta = $("#table").bootstrapTable('getSelections');
            if ($pdadta.length < 1) {
                swal({
                    title: "错误",
                    text: "选选择删除内容",
                    type: "error",
                    timer: 2000
                });
            }
            else {
                swal({
                    title: '确认删除吗',
                    text: "确认删除吗" + $pdadta.length + "记录",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    showLoaderOnConfirm: true,
                    confirmButtonText: "确认",
                    cancelButtonText: "取消",
                    preConfirm: function () {
                        return new Promise(function (resolve) {
                            var _postdata = {};
                            var ids = [];
                            $.each($pdadta, function (i, field) {
                                ids.push(field["id"]);
                            });
                            _postdata["ids"] = ids.join(",");
                            $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'new_delete'));}", {
                                method: 'POST',
                                data: _postdata,
                                dataType: 'json'
                            }).done(function (response) {
                                if (parseInt(response["status"]) === 1) {
                                    xc_edit_message({
                                        title: "提示",
                                        text: "删除成功",
                                        type: "success",
                                        timer: 1500
                                    });

                                    $("#table").bootstrapTable('refresh');
                                }
                                else {
                                    xc_edit_message({
                                        title: "错误",
                                        text: "删除失败",
                                        type: "error",
                                        timer: 2000
                                    });
                                }
                            });


                        });
                    },
                    allowOutsideClick: false
                })

            }

        })

    })
    $saechparas = null;
    function setseach() {
        $saechparas = {};
        $saechparas = $("#searchform").serializeArray();
    }
    $.extend($.fn.bootstrapTable.defaults, {
        method: 'post',
        pagination: true,
        sidePagination: 'server',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
//        showRefresh: true,
        onClickCell: function (field, value, row, $element) {


        },
        onLoadSuccess: function () {
//            $("#pfrom").find(".per").each(function () {
//                $(this).qrcode({
//                    text: $(this).attr("href"),
//                    height: 150,
//                    width: 150
//                });
//            })
        }
    });
    $.extend($.fn.bootstrapTable.columnDefaults, {
        align: 'center',
        valign: 'middle'
    });


    function operateFormatter(value, row, index) {
        var myhtml = [];
        if(row['type']==1){

        }
        if(row['status']==-1){
            myhtml.push(
                    '<a class="btn btn-primary btn-xs edit" data-status="1">',
                    '成功',
                    '</a>',
                    '<a class="btn btn-primary btn-xs edit" data-status="2">',
                    '失败',
                    '</a>'
            );
        }
        return myhtml.join('');
    }


    var operateEvents = {
        "click a.delete": function (e, value, row, index) {
            var _postdata = {};
            _postdata["ids"] = row["id"];
            swal({
                title: '确认删除吗',
                showCancelButton: true,
                closeOnConfirm: false,
                showLoaderOnConfirm: true,
                confirmButtonText: "确认",
                cancelButtonText: "取消",
                preConfirm: function () {
                    return new Promise(function (resolve) {
                        $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'new_delete'));}", {
                            method: 'POST',
                            data: _postdata,
                            dataType: 'json'
                        }).done(function (response) {
                            if (parseInt(response["status"]) === 1) {
                                xc_edit_message({
                                    title: "提示",
                                    text: "删除成功",
                                    type: "success",
                                    timer: 1500
                                });

                                $("#table").bootstrapTable('refresh');
                            }
                            else {
                                xc_edit_message({
                                    title: "错误",
                                    text: "删除失败",
                                    type: "error",
                                    timer: 2000
                                });

                            }
                        });

                        //  resolve();

                    });
                },
                allowOutsideClick: false
            })
        },
        'click a.edit': function (e, value, row, index) {
            var _postdata = {};
            _postdata["id"] = row["id"];
            _postdata["status"] =$(this).attr("data-status");
            $actindex = index;
            $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'share_withdraw_status'));}", {
                method: 'POST',
                data: _postdata,
                dataType: 'json'
            }).done(function (response) {
                if (parseInt(response["status"]) === 1) {
                    swal('操作成功!', '操作成功!', 'success');
                    $("#table").bootstrapTable('updateRow', {
                        index: $actindex,
                        row: {
                            status:_postdata['status']
                        }
                    });
                }
                else {
                    swal('操作失败!',response.msg, 'error');
                }
            });


        },
        'click a.wxpay': function (e, value, row, index) {
            var _postdata = {};
            _postdata["id"] = row["id"];
            $actindex = index;
            $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'share_withdraw_wx'));}", {
                method: 'POST',
                data: _postdata,
                dataType: 'json'
            }).done(function (response) {
                if (parseInt(response["status"]) === 1) {
                    swal('操作成功!', '操作成功!', 'success');
                    $("#table").bootstrapTable('updateRow', {
                        index: $actindex,
                        row: {
                            status:1
                        }
                    });
                }
                else {
                    swal('操作失败!',response.msg, 'error');
                }
            });


        },
    };

    var operatesorts = {
        'change input.sorts': function (e, value, row, index) {

            var _postdata = {};
            _postdata["id"] = row["id"];
            _postdata["sorts"] = $(this).val();
            $actindex = index;

            $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'updatesorts'));}", {
                method: 'POST',
                data: _postdata,
                dataType: 'json'
            }).done(function (response) {
                if (parseInt(response["status"]) === 1) {
                    xc_list_message({
                        title: "提示",
                        text: "操作成功",
                        type: "success",
                        timer: 1500
                    });

                    $("#table").bootstrapTable('updateRow', {
                        index: $actindex,
                        row: {
                            sort:  _postdata["sorts"]
                        }
                    });
                }
                else {
                    xc_list_message({
                        title: "错误",
                        text: "操作失败",
                        type: "error",
                        timer: 2000
                    });
                }
            });


        }
    };
    var operatestatus = {
        'click a': function (e, value, row, index) {
            var _postdata = {};
            _postdata["id"] = row["id"];
            _postdata["status"] = $(this).attr("data-value");
            $actindex = index;

            $.ajax("{php echo $this->createWebUrl($_GPC['do'], array('op'=>'midstatus'));}", {
                method: 'POST',
                data: _postdata,
                dataType: 'json'
            }).done(function (response) {
                if (parseInt(response["status"]) === 1) {
                    xc_list_message({
                        title: "提示",
                        text: "操作成功",
                        type: "success",
                        timer: 1500
                    });

                    $("#table").bootstrapTable('updateRow', {
                        index: $actindex,
                        row: {
                            status: -_postdata["status"]
                        }
                    });
                }
                else {
                    xc_list_message({
                        title: "错误",
                        text: "操作失败",
                        type: "error",
                        timer: 2000
                    });
                }
            });
        }
    };
    //格式化状态
    function formatstatus(value, row, index) {
        if (value == -1) {

            return '<a class="btn btn btn-default btn-xs" data-value="-1"  data-filed="status" > <i class="fa fa-square-o fa-lg"></i></a> ';
        }
        else {
            return '<a class="btn btn-primary  btn-xs"  data-value="1" data-filed="status" > <i class="fa fa-check-square-o fa-lg"></i></a>'
        }
    }
    function  formatpid(value, row, index) {
        if(typeof(htojb["pid"][value])==="undefined"){

            return "分类已删除";
        }
        else {
            return htojb["pid"][value];

        }
    }
    //格式化排序
    function formatsorts(value, row, index) {

        return ' <input class="sorts" value="'+value+'">';

    }

    function type_name(value, row, index){
        if(value==1){
            return '微信';
        }else if(value==2){
            return '支付宝';
        }else if(value==3){
            return '银行卡';
        }else if(value==4){
            return '后台提现';
        }
    }

    function info(value, row, index){
        var myhtml = [];
        if(row['type']==3){

        }else if(row['type']==4){
            myhtml.push(
                    '<p style="margin: 0;text-align: left;">操作账号：'+row['username']+'</p>'
            );
        }else{
            myhtml.push(
                    '<p style="margin: 0;text-align: left;">账号：'+row['username']+'</p>',
                    '<p style="margin: 0;text-align: left;">姓名：'+row['name']+'</p>'
            );
            if(row['area_name']!="" && row['area_name']!=null && row['area_code']!=null && row['area_code']!=""){
                myhtml.push(
                        '<p style="margin: 0;text-align:left;">国家/地区：'+row['area_name']+'（+'+row['area_code']+'）'+'</p>'
                );
            }
            myhtml.push(
                    '<p style="margin: 0;text-align: left;">手机号：'+row['mobile']+'</p>'
            );
            if(row['code']!="" && row['code']!=null){
                myhtml.push(
                        '<p style="margin: 0;text-align: left;">收款码：<img src="'+row['code']+'" width="200"/></p>'
                );
            }
        }
        return myhtml.join('');
    }

    function status(value, row, index){
        if(value==-1){
            return '待处理';
        }else if(value==1){
            return '成功';
        }else if(value==2){
            return '失败';
        }
    }
</script>
</body>
</html>